package com.kgc.sbt.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.kgc.sbt.api.GoodsApi;
import com.kgc.sbt.api.SlideShowApi;
import com.kgc.sbt.domain.Goods;
import com.kgc.sbt.domain.Slideshow;
import com.kgc.sbt.util.RequestResult;
import com.kgc.sbt.util.ResultBuildUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created on 2021/6/23.
 * <p>
 * Author: a123
 * <p>
 * Description:
 */
@RestController
@Api(tags = "轮播图展示，版本号：1.0.0")
public class SlideShowController {

    @Reference
    private SlideShowApi slideShowApi;

    /**
     * @author: zzw
     * @date: 2021/6/23
     * @return
     * @description: 轮播图展示
     */
    @GetMapping("/slideShow")
    @ApiOperation(value = "轮播图展示",notes = "支持统一返回")
    public RequestResult<List<Slideshow>> slideShow(){

        List<Slideshow> slideshows = slideShowApi.selectSlideShow();

        return ResultBuildUtil.success(slideshows);
    }

    /**
     * @author: zzw
     * @date: 2021/6/25
     * @return
     * @description: 根据轮播图的id查询商品信息
     */
    @GetMapping("/sliderById")
    @ApiOperation(value = "根据id查询商品信息",notes = "支持统一返回")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",required = true,value = "轮播图id")
    })
    public RequestResult<String> sliderById(@RequestParam Integer id){

        // 根据id查询轮播图信息
        Slideshow slideshow = slideShowApi.selectById(id);

        // 查询跳转链接
        String url = slideshow.getTourl();

        return ResultBuildUtil.success(url);
    }
}
